package com.komodo.island.gdx.dialog;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.actors.Button;
import com.badlogic.gdx.scenes.scene2d.actors.Image;
import com.komodo.island.gdx.Input;
import com.komodo.island.gdx.KomodoIsland;
import com.komodo.island.gdx.Persistence;
import com.komodo.island.gdx.screen.Screen;

public class PlayerSelectDialog extends Dialog {

	private Button touristButton;
	private Button scientistButton;
	private Button backButton;

	public PlayerSelectDialog(float width, float height, boolean stretch,
			Screen screen, Texture texture,KomodoIsland komodoIsland) {
		super(width, height, stretch, screen, texture,komodoIsland);
		// TODO Auto-generated constructor stub
		this.ID = Input.DIALOG_PLAYER_SELECT;
	}

	@Override
	public void init() {
		// TODO Auto-generated method stub
		// initByTexture(screen.texture);
		// setBackground(480*2, 320*2, 480, 320);
		background = new Image(backgroundName, new TextureRegion(
				komodoIsland.menuTexture, 480 * 2, 320 * 2, 480, 320));

		touristButton = new Button("tourist", new TextureRegion(texture, 240,
				0, 120, 200), new TextureRegion(texture, 360, 0, 120, 200));
		scientistButton = new Button("scientist", new TextureRegion(texture, 0,
				0, 120, 200), new TextureRegion(texture, 120, 0, 120, 200));
		backButton = new Button("back", new TextureRegion(texture,
				90 + 63 + 64 * 4, 200, 32, 32), new TextureRegion(texture, 90
				+ 63 + 64 * 4 + 32, 200, 32, 32));

	}

	@Override
	public void addElements() {
		// TODO Auto-generated method stub
		addActor(background);
		addActor(touristButton);
		addActor(scientistButton);
		addActor(backButton);
	}

	@Override
	public void setThePosition() {
		// TODO Auto-generated method stub

		scientistButton.x = 50;
		scientistButton.y = 50;

		touristButton.x = 298;
		touristButton.y = scientistButton.y;

		backButton.x = 15;
		backButton.y = 16;
	}

	@Override
	public void setTheListener() {
		// TODO Auto-generated method stub
		backButton.clickListener = new Button.ClickListener() {

			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
				if (Persistence.sound)
					komodoIsland.dialogSound.play(1);
				screen.exitScreen();
			}
		};

		touristButton.clickListener = new Button.ClickListener() {

			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
				if (Persistence.sound)
					komodoIsland.mainSound.play(1);
				if (Persistence.secondTourist)
				screen.komodoIsland
						.goToScreen(komodoIsland.touristScreen);
				else{
					komodoIsland.goToScreen(komodoIsland.storyTourist);
					if (!Persistence.secondTourist){
						Persistence.putBooleanInto("secondtourist",true);
						Persistence.secondTourist = true;
					}
					
				}
			}
		};
		scientistButton.clickListener = new Button.ClickListener() {

			public void clicked(Button arg0) {
				// TODO Auto-generated method stub'
				if (Persistence.sound)
					komodoIsland.mainSound.play(1);
				if (Persistence.secondScientist)
				screen.komodoIsland
						.goToScreen(komodoIsland.scientistScreen);
				else{
					komodoIsland.goToScreen(komodoIsland.storyScientist);
					
					if (!Persistence.secondScientist){
						Persistence.putBooleanInto("secondscientist",true);
						Persistence.secondScientist = true;
					}
					
				}
			}
		};
	}
}
